<?php
/**
 *
 * Projet Authentic CMS
 * @file 	   controller.php
 *
 * PHP version 5
 *
 *
 * @author     Poly Charly <CharlyPoly@gmail.fr>
 * @copyright  2009 Authentic Development Group
 * @license    GNU General Public License v3
 * @since      File available since Version 0.1.0
 * 
 */
class controller {
	protected $request;
	private $tpl = "";
	public  $vars;
	private $mod;
	
	const LAYOUT = 'layoutMod';

	public function __construct() {
		$this->vars = (object) NULL;
	}
	
	public final function init($request, $mod) {
		$this->request  = $request;
		$this->mod		= $mod;
	}
	
	protected function assign($name, $var) {
        if (!isset($this->vars->{$name})) {
            $this->vars->{$name} = $var;
        } else {
            die('SetVar must be use with not declared tpl vars !');
        }
    }
	
	protected function render($mod, $file) {
		if ($mod == controller::LAYOUT) {
			$this->tpl = file_get_contents(MODULES_DIR.$this->mod.DS.'templates'.DS.$file);
		}
	}
	
	public final function getWiew() {
		$wObj = (object) NULL;
		$wObj->content = $this->tpl;
		$wObj->vars	   = $this->vars;
		
		
		return $wObj;
	}
	
}
?>